using System;
using System.Configuration;

using Db4objects.Db4o;
using Db4objects.Db4o.Query;

namespace JingQiao.Ads.Infrastructure.Data.DB4O
{
    using Domain.Model.DomainObject;

    public partial class AdsContext  
    {
        public const string ConnectionString = "name=AdsContext";
        public const string ContainerName = "AdsContext";
        protected IObjectContainer _objectContainer;

        #region Constructors

        public AdsContext()
            : this(ConnectionString, ContainerName)
        {
        }

        public AdsContext(string connectionString)
            : this(connectionString, ContainerName)
        {
        }

        public AdsContext(string connectionString, string containerName)
        {
            string yapFileName = ConfigurationManager.ConnectionStrings[containerName].ConnectionString;
            this._objectContainer = Db4oEmbedded.OpenFile(Db4oEmbedded.NewConfiguration(), yapFileName);
        }

        #endregion

        #region ObjectSet Properties

        public IObjectSet Advertisement
        {
            get { return _advertisement ?? (_advertisement = this._objectContainer.QueryByExample(null)); }
        }
        private IObjectSet _advertisement;

        public IObjectSet ConfigInfo
        {
            get { return _configInfo ?? (_configInfo = this._objectContainer.QueryByExample(null)); }
        }
        private IObjectSet _configInfo;

        public IObjectSet Destination
        {
            get { return _destination ?? (_destination = this._objectContainer.QueryByExample(null)); }
        }
        private IObjectSet _destination;

        public IObjectSet DestPositionAd
        {
            get { return _destPositionAd ?? (_destPositionAd = this._objectContainer.QueryByExample(null)); }
        }
        private IObjectSet _destPositionAd;

        public IObjectSet Position
        {
            get { return _position ?? (_position = this._objectContainer.QueryByExample(null)); }
        }
        private IObjectSet _position;

        public IObjectSet Template
        {
            get { return _template ?? (_template = this._objectContainer.QueryByExample(null)); }
        }
        private IObjectSet _template;

        #endregion
    }
}
